package com.misty.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.misty.blog.service.BlogService;
import com.misty.blog.service.ConcernListService;
import com.misty.common.bean.Result;
import com.misty.dao.domain.ConcernList;
import com.misty.dao.dto.BlogDto;
import com.misty.dao.mapper.BlogLikesMapper;
import com.misty.dao.mapper.ConcernListMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 博客点赞表 服务实现类
 * </p>
 *
 * @author cthulhu
 * @since 2022-12-02
 */
@Service
public class ConcernListServiceImpl extends ServiceImpl<ConcernListMapper, ConcernList> implements ConcernListService {

    @Resource
    private BlogLikesMapper blogLikesMapper;

    @Resource
    private ConcernListMapper concernListMapper;
    @Resource
    private BlogService blogService;

    @Override
    public Boolean isConcern(Integer blogId,Integer CurUserId,Integer beConcernId){
        if(beConcernId == null){
            Result<?> result = blogService.selectByIdWithUser(blogId);
            BlogDto data = (BlogDto) result.getData();
            beConcernId= data.getUser().getId();
        }
        Wrapper<ConcernList> queryWrapper = Wrappers
                .<ConcernList>lambdaQuery()
                .eq(ConcernList::getUserId, CurUserId)
                .eq(ConcernList::getFollowUserId,beConcernId);
        return concernListMapper.selectCount(queryWrapper) > 0 ? true:false;
    }
}
